/**
 * Program   :   CodeAssistantAction.java
 * Author    :   shadow guo
 * Create    :   2013-6-19 下午2:16:45
 *
 * Copyright 2008 by Tongfu Information Technology Co. Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Tongfu Information Technology Co. Ltd. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Tongfu Information Technology Co. Ltd.
 * 
 */
package com.tongfusoft.web.core.action.codeassistant;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.tongfusoft.web.core.action.BaseAction;
import com.tongfusoft.web.core.service.codeassistant.ICodeAssistantService;

public class CodeAssistantAction extends BaseAction {
	/**
	 * Logger for this class
	 */
	private static final Log logger = LogFactory
			.getLog(CodeAssistantAction.class);

	private ICodeAssistantService codeAssistantService;

	public ICodeAssistantService getCodeAssistantService() {
		return codeAssistantService;
	}

	public void setCodeAssistantService(
			ICodeAssistantService codeAssistantService) {
		this.codeAssistantService = codeAssistantService;
	}
	
	public void getAllTable(){
		super.outJson(this.getCodeAssistantService().getAllTable((String) this.getParamByName("dbId")));
	}
	
	public void genBeanCode(){
		super.outJson(this.getCodeAssistantService().genBeanCode((String) this.getParamByName("dbId"), (String) this.getParamByName("tableName")));
	}

	public void parserSql() {
		Map<String, Object> result = new HashMap<String,Object>();
		
		result = this.getCodeAssistantService().parserSQL(
					(String) this.getParamByName("listSql"));
		
		super.outJson(result);
	}

	public void genListCode() {
		String jsonStr = (String) this.getParamByName("listData");
		if (logger.isDebugEnabled()) {
			logger.debug(jsonStr);
		}
		
		Map<String, String> result = new HashMap<String, String>();

		result.put("yaml", this.getCodeAssistantService().genListYaml(jsonStr));
		result.put("grid", this.getCodeAssistantService().genJqGrid(jsonStr));

		super.outJson(result);
	}
}
